﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Core ;

namespace NUnit_0414
{
    [TestFixture ]
    public class TestClass
    {
        #region properties
        private int demondValue { get; set; }

        private Customer demondCustomer { get;set; }
        #endregion

        #region setup and teardown
        /// <summary>
        /// init the base info the class0
        /// </summary>
        [TestFixtureSetUp ]
        public void SetUpMethod()
        {
            this.demondValue = 10;
            this.demondCustomer = new Customer();
        }

        /// <summary>
        /// dipose the resource of the test object
        /// </summary>
        [TearDown ]
        public void TearDownMethod()
        { 
        }
        #endregion

        #region test functions 
        [Test]
        [Category ("Int")]
        public void IsEqual()
        {
            int theExpectValue = 10;
            StringBuilder ErrMessage = new StringBuilder();
            ErrMessage.AppendFormat("the demond value is not equal to {0}!", theExpectValue);
            Assert.AreEqual(10, demondValue, ErrMessage .ToString ());
        }

        [Test,Category ("Customer")]
        public void IsCustomerSame()
        {           
            Customer expectCust = new Customer("Ding", 1);
            Assert.IsNotNull(this.demondCustomer);
            Assert.AreSame(expectCust, demondCustomer, CreateErrorMessage("the two customers are not the same",null));
        }

        [Test]
        //[ExpectedException (typeof(DivideByZeroException))]
        [Ignore ("Don't to test this function")]
        public void DivideByZero()
        {
            int zero = 10;
            int devideNum = 10;
            int result = devideNum / zero;
            //Assert.Fail("Should throw a divideByZeroException");
        }
        #endregion

        #region assitant functions
        /// <summary>
        /// Create the error Message  by the StringBuilder's format 
        /// </summary>
        /// <param name="format"></param>
        /// <param name="args"></param>
        public string CreateErrorMessage(string format, params  object[] args)
        {
            StringBuilder strBuilder = new StringBuilder();
            if (args!=null && args.Length > 0)
                strBuilder.AppendFormat(format, args);
            else
                strBuilder.AppendFormat(format);
            return strBuilder.ToString();
        }
        #endregion
    }


    [TestFixture ]
    public class TestClass0
    {
        /// <summary>
        /// get and set the price
        /// </summary>
        public int Price { get; set; }

        public TestClass0() {
            this.Price = 10;
        }

        [Test]
        public void PriceIsEqual()
        {
            Assert.AreEqual(9, this.Price, "the price is equal to 9");
        }
    }


    public class AllTest
    {
        [Suite]
        public static TestSuite Suite
        {
            get {
                TestSuite suite = new TestSuite("AllTest");
                suite.Add(new TestClass());
                suite.Add(new TestClass0());
                return suite;
            }
        }
    }
}
